package com.longyu.worker.controller;

import com.faneui.common.bean.BaseResp;
import com.faneui.common.exception.BusinessException;
import com.google.common.collect.Lists;
import com.longyu.worker.bootup.AbstractController;
import com.longyu.worker.bean.LoginReq;
import com.longyu.worker.bean.QueryUserListResp;
import com.longyu.worker.bean.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("用户")
@RestController
@RequestMapping("user")
public class UserController extends AbstractController {


    @ApiOperation(value = "登录", notes = "  ")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public BaseResp login(@RequestBody LoginReq req) throws BusinessException {
        BaseResp resp = new BaseResp();
        try {
            if(!"admin".equals(req.getUserName())){
                //
                throw new BusinessException("登录错误") ;
            }
        } catch (Exception ex) {
            logger.error("", ex);
            resp.setSuccess(false);
            resp.setMsg(ex.getMessage());
        }
        return resp;
    }

    @ApiOperation(value = "用户列表", notes = "  ")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public QueryUserListResp list(@ModelAttribute User user) throws BusinessException {
        QueryUserListResp resp = new QueryUserListResp();
        try {
            List<User> userList = Lists.newArrayList() ;
            User user1 = new User();
            user1.setId("1");
            user1.setUserName("范睿");
            user1.setPassword("123456");
            userList.add(user1) ;

            User user2 = new User();
            user2.setId("1");
            user2.setUserName("范睿");
            user2.setPassword("123456");
            userList.add(user2) ;

            resp.setUserList(userList);
        } catch (Exception ex) {
            logger.error("", ex);
            resp.setSuccess(false);
            resp.setMsg(ex.getMessage());
        }
        return resp;
    }

}
